/*
 * nume: client-to-client-server.h
 * autor: ~D
 * descriere: partea de server a clientului... clientul asculta
 * pe un port pentru conexiuni de la alti clienti
 * pentru fiecare client coectat creaza un nou thread
 * tabela de modificarei
 *   12 iunie 2007 - ~D - prima versiune
 */

#include "client-to-client-server.h"
#include "client-to-client-thread-server.h"

#include <stdlib.h>

ClientToClientServer::ClientToClientServer(QObject *parent)
    : QTcpServer(parent) {
    fortunes << tr("You've been leading a dog's life. Stay off the furniture.")
             << tr("You've got to think about tomorrow.")
             << tr("You will be surprised by a loud noise.")
             << tr("You will feel hungry again in another hour.")
             << tr("You might have mail.")
             << tr("You cannot kill time without injuring eternity.")
             << tr("Computers are not intelligent. They only think they are.");
}

void ClientToClientServer::incomingConnection(int socketDescriptor) {
    QString fortune = fortunes.at(qrand() % fortunes.size());
    ClientToClientThreadServer *thread = new ClientToClientThreadServer(socketDescriptor, fortune, this);
    connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
    thread->start();
}
